package com.lw.vue_shop_server.controller;

import com.lw.vue_shop_server.service.impl.CategoryServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
public class CategoryController {
    @Autowired
    public CategoryServiceImpl categoryService;

    @GetMapping("categories")
    public Map getCategories(HttpServletRequest request){
        Integer pagenum = Integer.parseInt(request.getParameter("pagenum"));
        Integer pagesize = Integer.parseInt(request.getParameter("pagesize"));
        if(pagenum==-1 || pagesize==-1){
            return categoryService.getCategories(null,null);
        }else {
            return categoryService.getCategories(pagenum,pagesize);
        }
    }
}
